#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import requests
import json
import sys
import time
import datetime
import re
import sqlite3
import ffmpeg

sql_creat_table = "DROP TABLE IF EXISTS xzt;CREATE TABLE xzt (id INTEGER,N TEXT,T TEXT,A TEXT,B TEXT,C TEXT,D TEXT,Q TEXT,Qs TEXT,PRIMARY KEY(id AUTOINCREMENT));DROP TABLE IF EXISTS pdt;CREATE TABLE pdt (id INTEGER,N TEXT,T TEXT,Q TEXT,Qs TEXT,Q1 TEXT,PRIMARY KEY(id AUTOINCREMENT))"
sql_creat_table_pdt = "DROP TABLE IF EXISTS pdt;CREATE TABLE pdt (id INTEGER,N TEXT,T TEXT,Q TEXT,Qs TEXT,Q1 TEXT,PRIMARY KEY(id AUTOINCREMENT))"

# conn = sqlite3.connect(':memory:')
conn = sqlite3.connect("/dev/shm/m.db")
cur = conn.cursor()
cur.executescript(sql_creat_table)

with open(os.path.join(os.path.dirname(__file__), "选择题.txt"), "r") as f:
    s = f.read()
with open(os.path.join(os.path.dirname(__file__), "选择题答案.txt"), "r") as f:
    q = f.readlines()
lines = re.split("\n{2,}", s)
for i, line in enumerate(lines):
    tm = line.split("\n")
    sql_insert = f"INSERT INTO xzt ('N','T','A','B','C','D','Q','Qs') VALUES('{q[i].split('.')[0]}','{tm[0]}','{tm[1]}','{tm[2]}','{tm[3]}','{tm[4]}','{q[i].strip().split('.')[1]}','{q[i].strip()}')"
    cur.execute(sql_insert)


with open(os.path.join(os.path.dirname(__file__), "判断题.txt"), "r") as f:
    s = f.readlines()
    print(len(s))
with open(os.path.join(os.path.dirname(__file__), "判断题答案.txt"), "r") as f:
    q = f.readlines()
    print(len(q))
with open(os.path.join(os.path.dirname(__file__), "判断题答案1.txt"), "r") as f:
    q1 = f.readlines()
    print(len(q1))
for i, line in enumerate(s):
    tm = line.strip()
    sql_insert = f"INSERT INTO pdt ('N','T','Q','Qs','Q1') VALUES('{q[i].split('.')[0]}','{tm}','{q[i].strip().split('.')[1]}','{q[i].strip()}','{q1[i].strip().split('.')[1]}')"
    cur.execute(sql_insert)

cur.execute("select * from pdt")
rows = cur.fetchall()
conn.commit()
cur.close()
conn.close()
